package com.example.springboot_redis.controller;

import com.example.springboot_redis.Dao.Po.StudentPo;
import com.example.springboot_redis.mapper.StudentMapper;
import com.example.springboot_redis.service.StudentI;
import com.example.springboot_redis.service.serviceImpl.RedisServiceImpl;
import org.junit.runners.Parameterized;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
@RequestMapping
public class StudentController {
    private final StudentI studentI;
    private final RedisServiceImpl redisService;
    public StudentController(StudentI studentI, RedisServiceImpl redisService) {
        this.studentI = studentI;
        this.redisService = redisService;
    }

    @GetMapping("/student")
    public ResponseEntity<List<StudentPo>> student() {
        // 返回 student.html 页面
        return ResponseEntity.ok(studentI.getAllStudents());
    }
    @GetMapping("/redis")
    public ResponseEntity<StudentPo> redis(@RequestParam String key) {


        return ResponseEntity.ok(redisService.get(key));
    }
    @GetMapping("/")
    public ModelAndView index () {
        return new ModelAndView("index/index");
    }
}
